package com.xuxu.blog.entity.bean;

import com.xuxu.blog.entity.PermissonEntity;
import com.xuxu.blog.entity.UserEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

/**
 * @className: UserInfo
 * @author: Maxuxu
 * @date: 2022/8/24 9:10
 * @description: 自定义实体类表，数据库不存在，主要负责封装用户数据
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Slf4j
public class UserInfo implements Serializable {
    private int id;
    private String username;
    private String nick;
    private int age;
    private String sex;
    private String address;
    private String avatar;
    private String token;

    private String openid;
    // ip地址
    private String ip;
    // IP地址对应的真实地址
    private String ipAddress;

    private String regtime;

    private String introduce;

    private Integer points;
    private int role;
    private List<Integer> roles;
    private Set<PermissonEntity> permissions;

    public UserInfo(UserEntity user) {
        this.id = user.getId();
        this.age = user.getAge();
        this.sex = user.getSex();
        this.address = user.getAddress();
        this.token = user.getToken();
        this.username = user.getUsername();
        this.nick = user.getNick();
        this.regtime = user.getRegtime();
        this.role=user.getRole();
        this.openid = user.getOpenid();
        this.points=user.getPoints();
        this.roles=user.getRoles();
        this.permissions=user.getPermissions();

        this.avatar = user.getAvatar() != null ? user.getAvatar() : "https://img2.baidu.com/it/u=2285567582,1185119578&fm=26&fmt=auto";
        this.introduce = user.getIntroduce() != null ? user.getIntroduce() : "数据为空，请介绍一下自己吧";

    }
}
